import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/page/home'
import Blocks from '@/page/blocks'
import BlockDetail from '@/page/blockdetail'
import Transactions from '@/page/transactions'
import TransactionDetail from '@/page/transactiondetail'

import MEHome from '@/MEpage/MEhome'
import MEBlocks from '@/MEpage/MEblocks'
import MEBlockDetail from '@/MEpage/MEblockdetail'
import METransactions from '@/MEpage/MEtransactions'
import METransactionDetail from '@/MEpage/MEtransactiondetail'
Vue.use(Router)

function browserRedirect() {
  var flag = 1;
  var ua= navigator.userAgent.toLowerCase();
  var ipad= ua.match(/ipad/i) == "ipad";
  var iphone= ua.match(/iphone os/i) == "iphone os";

  var mid= ua.match(/midp/i) == "midp";

  //midp，即Mobile Internet Device pad，一种新的“比智能电话大，比笔记本小”的互联网终端。
  var uc7= ua.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var uc= ua.match(/ucweb/i) == "ucweb";
  var android= ua.match(/android/i) == "android";
  var ce= ua.match(/windows ce/i) == "windows ce";
  var mobile= ua.match(/windows mobile/i) == "windows mobile";
  if (ipad|| iphone|| mid|| uc7|| uc || android|| ce|| mobile) {
      //跳转移动端页面
      // window.location.href="http://www.wanshaobo.com/mobile/index.html";
      return 1;
  } else {
      //跳转pc端页面
      // window.location.href="http://www.wanshaobo.com/index.html";
      return 2;
  }

}

export default new Router({
  routes: [
    {
      path: '/',
      redirect: to=> {
        if (browserRedirect()===2){
          return '/home';
        } else {
          return '/MEhome';
        }
      }
    }, {
      path: '/home',
      name: 'home',
      component: Home
    },{
      path: '/MEhome',
      name: 'MEhome',
      component: MEHome
    },{
      path: '/blocks',
      component: Blocks
    }, {
      name: 'blockdetail',
      path: '/blocks/:id',
      component: BlockDetail
    }, {
      path: '/transactions',
      component: Transactions
    }, {
      name: 'transactiondetail',
      path: '/transactions/:id',
      component: TransactionDetail
    }, {
      path: '/MEblocks',
      component: MEBlocks
    }, {
      path: '/MEblocks/:id',
      component: MEBlockDetail
    }, {
      path: '/MEtransactions',
      component: METransactions
    }, {
      path: '/MEtransactions/:id',
      component: METransactionDetail
    }
  ]
})
